import MyTable from '@/components/MyTable';
import { getResult } from '@/services/sys/attribute';
import {
  findByWalletBackPageWithdrawal,
  withdrawalStatus,
} from '@/services/sys/log';
import { Link } from '@umijs/max';
import { Button, Popconfirm, Typography } from 'antd';
import React, { useState } from 'react';
const { Paragraph } = Typography;

const columns = [
  {
    title: '编号',
    dataIndex: 'id',
    search: false,
    key: 'id',
  },

  {
    title: '经销商',
    dataIndex: 'authName',
    key: 'authName',
    search: true,
    render: (_: any, row: API.Users, index: number, action: any) => {
      return <Paragraph copyable={{ text: getCopyText(row) }}>{_}</Paragraph>;
    },
  },
  {
    title: '提现金额',
    dataIndex: 'requestAmount',
    valueType: 'money',
    key: 'requestAmount',
    search: false,
  },
  /* , {
     title: '手续费',
     dataIndex: 'taxes',
     valueType: 'money',
     key: 'taxes',
     search: false,
   }, {
     title: '实际金额',
     dataIndex: 'amount',
     valueType: 'money',
     key: 'amount',
     search: false,
   }*/
  {
    title: '提现方式',
    dataIndex: 'backName',
    key: 'backName',
    search: false,
  },

  {
    title: '状态',
    dataIndex: 'status',
    // valueType: 'select',
    key: 'status',
    search: true,
    valueEnum: await getResult('paymentwithdrawalStatus'),
    valueType: 'select',
  },

  {
    title: '收款人姓名',
    dataIndex: 'name',
    valueType: 'name',
    key: 'name',
    search: false,
  },
  {
    title: '申请时间',
    key: 'createDate',
    dataIndex: 'createDate',
    valueType: 'dateTime',
    search: false,
  },
  {
    title: '更新时间',
    dataIndex: 'updateDate',
    valueType: 'dateTime',
    hideInSearch: true,
    key: 'updateDate',
  },
  {
    title: '操作员',
    key: 'operatorName',
    dataIndex: 'operatorName',
    search: false,
  },
  {
    title: '操作',
    key: 'option',
    valueType: 'option',
    render: (_: any, row: API.Users, index: number, action: any) => [
      row?.status == 2 ? (
        <Popconfirm
          title={'通过确定吗！'}
          onConfirm={() => {
            withdrawalStatus(row?.id, 1).then((res) => {
              //   refresh ()
              action.reload();
            });
          }}
        >
          <Button type="primary">通过</Button>{' '}
        </Popconfirm>
      ) : (
        ''
      ),
      row?.status == 2 ? (
        <Popconfirm
          title={'未通过确定吗！'}
          onConfirm={() => {
            withdrawalStatus(row?.id, 3).then((res) => {
              //  refresh ()
              action.reload();
            });
          }}
        >
          <Button type="primary" danger>
            未通过
          </Button>{' '}
        </Popconfirm>
      ) : (
        ''
      ),
      <Link to={'/finance/show/' + row?.id}>详细</Link>,
    ],
  },
];
const formatNumber = (n) => {
  n = n.toString();
  return n[1] ? n : `0${n}`;
};
const formatTimeAll = (date: {
  getFullYear: () => any;
  getMonth: () => number;
  getDate: () => any;
  getHours: () => any;
  getMinutes: () => any;
  getSeconds: () => any;
}) => {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();

  return (
    [year, month, day].map(formatNumber).join('-') +
    ' ' +
    [hour, minute, second].map(formatNumber).join(':')
  );
};
const getCopyText = (data) => {
  // @ts-ignore
  let arr: [any] = [];
  arr.push('姓名:' + data?.name);
  arr.push('订单号:' + data?.sn);
  arr.push('提现金额:' + data?.requestAmount);
  arr.push('申请时间:' + formatTimeAll(new Date(data?.createDate)));
  arr.push('提现方式:' + data?.backName);
  arr.push('卡号:' + data?.backCardNo);
  arr.push('手机号:' + data?.backPhone);
  arr.push('地址:' + data?.backAddress);

  return arr.join(';\n\t\t');
};
const Withdrawal: React.FC<any> = (props) => {
  const [activeKey, setActiveKey] = useState<string>('tab1');

  return (
    <MyTable
      search={true}
      request={findByWalletBackPageWithdrawal}
      columns={columns}
    />
  );
};
export default Withdrawal;
